--- sharelite.c.orig    Mon Nov 14 15:37:08 2005
+++ sharelite.c Mon Nov 14 15:37:41 2005
@@ -1,3 +1,7 @@
+#include "EXTERN.h"
+#include "perl.h"
+#include "XSUB.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
@@ -151,7 +155,7 @@ Node *_add_segment(Share *share) {
   Node *node;
   int  flags;
 
-  if ((node = (Node *) malloc(sizeof(Node))) == NULL) 
+  if ((node = (Node *) safemalloc(sizeof(Node))) == NULL) 
     return NULL; 
   node->next = NULL;
 
@@ -196,7 +200,7 @@ int _detach_segments(Node *node) {
   while(node != NULL) {
     next_node  = node->next;
     if (shmdt((char *) node->shmaddr) < 0) return -1;
-    free(node);
+    safefree(node);
     node = next_node;
   }
   return 0;             
@@ -329,7 +333,7 @@ int read_share(Share *share, char **data
   node   = share->head;
   left = length = node->shmaddr->length;
 
-  if ((pos = *data = (char *) malloc( length )) == NULL)
+  if ((pos = *data = (char *) safemalloc( length )) == NULL)
     return -1;
 
   while(left) {
@@ -379,7 +383,7 @@ again:
     segment_size = SHM_SEGMENT_SIZE; 
   }
 
-  if ((node = (Node *) malloc(sizeof(Node))) == NULL) 
+  if ((node = (Node *) safemalloc(sizeof(Node))) == NULL) 
     return NULL;
   if ((node->shmid = shmget(key, segment_size, flags)) < 0)
     return NULL;
@@ -387,7 +391,7 @@ again:
     return NULL;
   node->next = NULL;
 
-  if ((share = (Share *) malloc(sizeof(Share))) == NULL) 
+  if ((share = (Share *) safemalloc(sizeof(Share))) == NULL) 
     return NULL;
   share->key       = key;
   share->next_key  = key + 1;
@@ -460,7 +464,7 @@ int destroy_share (Share *share, int rmi
       return -1;
   }
 
-  free(share);
+  safefree(share);
   
   return 0;
 }

